package com.woniu.controller;

import com.woniu.entity.PageResult;
import com.woniu.entity.Result;
import com.woniu.pojo.Magnet;
import com.woniu.pojo.Pda;
import com.woniu.service.IMagnetService;
import com.woniu.service.IPdaService;
import com.woniu.vo.MagnetQueryVo;
import com.woniu.vo.PdaQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author long
 * @since 2022-10-12
 */
@RestController
@RequestMapping("/pda")
@Api(tags = "手持PDA管理")
public class PdaController extends BaseController{
    @Autowired
    private IPdaService pdaService;

    @ApiOperation("分页搜索")
    @PostMapping("/search/{currentPage}/{pageSize}")
    public Result search(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody PdaQueryVo pdaQueryVo){
        PageResult pageResult = pdaService.search(currentPage, pageSize, pdaQueryVo);
        return toDataResult(pageResult);
    }

    @ApiOperation("添加PDA")
    @PostMapping
    public Result add(@RequestBody Pda pda){
        boolean flag = pdaService.save(pda);
        return toResult(flag);
    }

    @ApiOperation("删除PDA")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id){
        boolean flag = pdaService.removeById(id);
        return toResult(flag);
    }

    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    public Result queryById(@PathVariable Long id){
        Pda pda = pdaService.getById(id);
        return toDataResult(pda);
    }

    @ApiOperation("修改PDA")
    @PutMapping
    public Result edit(@RequestBody Pda pda){
        boolean flag = pdaService.updateById(pda);
        return toResult(flag);
    }
    @ApiOperation("查询所有")
    @GetMapping
    public Result queryAll(){
        List<Pda> pdaList = pdaService.list();
        return toDataResult(pdaList);
    }
}
